﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Reflection;
using System.IO;
using System.Data;
using System.Windows.Forms;
using System.Net;
using System.Diagnostics;


using Hydrobase;
namespace RSSApplicationUpdater
{
    public class RssFeedCollection:CollectionBase 
    {
        List <UpdateFeedInfo> list;
        /// <summary>
        /// Adds  feed to the colection
        /// </summary>
        /// <param name="releasestate">the state of application's Release State</param>
        /// <param name="feed">the feed's url</param>
        public  void Add(string releasestate, string feed)
        {

            try
            {
                if ((releasestate != null) && (feed != null))
                {


                    UpdateFeedInfo tmp = new UpdateFeedInfo();
                    tmp.ReleaseState = releasestate;
                    tmp.Feed = feed;
                    list.Add(tmp);

                    
                }


            }
            catch (Exception e)
            {

                Core.errorreport(e);
            }

        }
        /// <summary>
        /// Adds many feeds to the colection
        /// </summary>
        /// <param name="release">the state of application's Release State</param>
        /// <param name="feed">the feed's url</param>
        public void AddRange(string[] release, string[] feed)
        {
            try
            {
                int i;
                if ((release != null) && (feed != null))
                {
                    for(i =0;i<release.Length ;i++)
                    {
                       this.Add(release[i],feed[i]);


                    }
                    

                }


            }
            catch (Exception e)
            {

                Core.errorreport(e);
            }




        }

        /// <summary>
        /// Deletes the feed with given info
        /// </summary>
        /// <param name="releasestate">the state of application's Release State</param>
        /// <param name="feed">the feed's url</param>
        public void Remove(string releasestate, string feed)
        {

            try
            {
                if ((feed != null) &&(releasestate !=null))
                {

                    foreach (UpdateFeedInfo item in list)
                    {

                        if ((item.Feed == feed) || (item.ReleaseState == releasestate))
                        {

                            list.Remove(item);
                        }

                    }

                  
                   


                }


            }
            catch (Exception e)
            {

                Core.errorreport(e);
            }

        }
        /// <summary>
        /// Returs the index of the feed that is in this state or -1 if error ocures
        /// </summary>
        /// <param name="releasestate">the state of application's Release State</param>
        /// <returns> Returs the index of the feed that is in this state or -1 if error ocures</returns>
        public int IndexOf(string releasestate)
        {
            try
            {
                int ap=0,i;
                if (releasestate != null)
                {


                    for (i=0;i<list.Count;i++)
                    {
                        if (list[i].ReleaseState == releasestate)
                        {
                            ap = i;
                            break;
                            
                        }


                    }
                  

                }
                return ap;


            }
            catch (Exception e)
            {

                Core.errorreport(e);
                return -1;
            }


        }
    }
    /// <summary>
    /// Class that contains info of aa Feed
    /// </summary>
    public class UpdateFeedInfo
    {
        string release,feed;
        public string ReleaseState
        {
            get { return release; }
            set{release=value; }

        }
        public  string Feed
        {get{return feed;}
            set{feed=value;}


        }


    }
}
